
/**
 * Module dependencies.
 */

var express = require('express');
var http = require('http');
var url  = require('url');
var path = require('path');


var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'app/views'));
app.set('view engine', 'jade');
//用来设置网站的图标，参数为图标的路径。如果不指明，则用默认的express图标
//app.use(express.favicon(path.join(__dirname, '../public/img/favicon.ico')))
app.use(express.favicon());
app.use(app.router);
//对请求内容进行解析，支持json、 application/x-www-form-urlencoded、multipart/form-data 格式数据的解析。也就是说ajax和form发送请求时，都会经过它的处理，方便在req中获取相应的请求值
//在express中处理文件上传也是用它，可以给出参数指明上传文件存放的路径，比如：app.use(express.bodyParser({uploadDir:'./uploads'}))
// app.use(express.bodyParser());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
//为了支持put、delete等HTTP方法，不过要客户端配合，包含相应的_method参数,在表单设置<input type="hidden" name="_method" value="put" />
app.use(express.methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
//不压缩html源码
app.locals.pretty = true;

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

//路由规则
require("./config/router")(app);

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});
